package com.kll.carolinehmibiz

import android.content.Context
import com.kll.carolinehmibiz.model.OperateListener
import com.kll.carolinehmibiz.net.bean.AddPhoto
import com.kll.carolinehmibiz.net.bean.GetUserInfoResponse
import com.kll.carolinehmibiz.presenter.AccountPresenter
import com.kll.carolinehmibiz.presenter.FamilyPresenter
import com.kll.carolinehmibiz.presenter.LoginPresenter
import com.kll.carolinehmibiz.presenter.SystemPresenter
import java.io.File

/**
 * ====================================================
 * Created by Ziliang Cai on 2021/12/06 21:21
 * <a href="mailto:752577456@qq.com">Contact me</a>
 * ====================================================
 */
class OperationManager {

    private lateinit var mContext: Context

    companion object {

        private var mInstance: OperationManager? = null

        @Synchronized
        fun getInstancce(): OperationManager {
            if(mInstance == null) {
                mInstance = OperationManager()
            }
            return mInstance!!
        }
    }

    fun init(context: Context) {
        mContext = context.applicationContext
    }

    /**
     * 获取设备激活状态
     */
    fun getDeviceStatus(listener: OperateListener) {
        AccountPresenter.getInstance(mContext).getDeviceStatus(listener)
    }

    /**
     * 激活设备
     *
     * @param mobile 手机号
     * @param verifyCode 验证码
     */
    fun activeDevice(mobile: String, verifyCode: String, listener: OperateListener) {
        AccountPresenter.getInstance(mContext).activeDevice(mobile, verifyCode, listener)
    }

    /**
     * 获取系统菜单
     */
    fun getSystemAllMenus(parentId: Int, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getSystemAllMenus(parentId, listener)
    }

    /**
     * 获取次级菜单详情
     * @param menuId 菜单ID
     *
     */
    fun getSystemMenuDetail(menuId: Int, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getSystemMenuDetail(menuId, listener)
    }

    /**
     * 获取验证码
     */
    fun getVerifyCode(mobile: String, listener: OperateListener) {
        LoginPresenter.getInstance(mContext).getVerifyCode(mobile, listener)
    }

    /**
     * 用户登录
     * @param verifyCode 验证码
     * @param mobile 手机号
     */
    fun login(verifyCode: String, mobile: String, listener: OperateListener) {
        LoginPresenter.getInstance(mContext).login(mobile, verifyCode, listener)
    }

    /**
     * 重置密码
     * @param mobile 手机号
     * @param verifyCode 验证码
     * @param pwd 密码
     */
    fun resetPwd(mobile: String, verifyCode: String, pwd: String, listener: OperateListener) {
        LoginPresenter.getInstance(mContext).resetPwd(mobile, verifyCode, pwd, listener)
    }

    /**
     * 判断是否登录
     */
    fun isLogin(): Boolean {
        return LoginPresenter.getInstance(mContext).isLogin()
    }

    /**
     * 退出登录
     */
    fun logout() {
        LoginPresenter.getInstance(mContext).logout()
    }

    /**
     * 用户注册
     * @param sn sn码
     * @param mobile 手机号
     * @param verifyCode 验证码
     */
    fun register(sn: String, mobile: String, verifyCode: String, listener: OperateListener) {
        LoginPresenter.getInstance(mContext).register(sn,mobile,  verifyCode, listener)
    }

    /**
     * 获取用户信息
     */
    fun getUserInfo(operateListener: OperateListener) {
        AccountPresenter.getInstance(mContext).getUserInfo(operateListener)
    }

    /**
     * 修改用户信息
     */
    fun editUserInfo(userInfo: GetUserInfoResponse, listener: OperateListener) {
        AccountPresenter.getInstance(mContext).editUserInfo(userInfo, listener)
    }

    /**
     * 获取分配客服
     *
     * @param type 客服类型 1：默认客服，2：基因检测，3：全息影像筛查，4：饮食检测，5：失忆预防检测，6：中医检测，7；睡眠呼吸检测，8；中医康复，9；饮食康复，10；运动健康，11；再生医学康复，12；睡眠障碍康复，13；自助问诊
     */
    fun getAssignCustomerService(type: Int, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getAssignCustomerService(type, listener)
    }

    /**
     * 添加家人
     *
     * @param mobile 手机号
     * @param avatar 头像url
     * @param firstName 姓氏
     * @param lastName 名
     * @param remark 备注
     */
    fun addFamily(mobile: String, avatar: String, firstName: String, lastName: String, remark: String, listener: OperateListener) {
        FamilyPresenter.getInstance(mContext).addFamily(mobile, avatar, firstName, lastName, remark, listener)
    }

    /**
     * 编辑家人
     *
     * @param familyId 家人ID
     * @param mobile 手机号
     * @param avatar 头像url
     * @param firstName 姓氏
     * @param lastName 名
     * @param remark 备注
     */
    fun editFamily(familyId: Int,  mobile: String, avatar: String, firstName: String, lastName: String, remark: String, listener: OperateListener){
        FamilyPresenter.getInstance(mContext).editFamily(familyId, mobile, avatar, firstName, lastName, remark, listener)
    }

    /**
     * 获取家人列表
     *
     */
    fun getFamily(listener: OperateListener) {
        FamilyPresenter.getInstance(mContext).getFamily(listener)
    }

    /**
     * 获取用户活跃的腾讯云IM用户id
     */
    fun getTencentId(tencentUserId: String, listener: OperateListener) {
        FamilyPresenter.getInstance(mContext).getTencentId(tencentUserId, listener)
    }
    /**
     * 获取用户活跃的腾讯云IM用户id
     */
    fun getRoomId(callUserId: String, listener: OperateListener) {
        AccountPresenter.getInstance(mContext).getRoomId(callUserId, listener)
    }
    /**
     * 删除家人
     * @param familyId 家人ID
     */
    fun delFamily(familyId: Int, listener: OperateListener) {
        FamilyPresenter.getInstance(mContext).delFamily(familyId, listener)
    }

    fun getUserSig(listener: OperateListener){
        AccountPresenter.getInstance(mContext).getUserSig(listener)
    }

    /**
     * 获取首页轮播图
     */
    fun getHomePageAds(listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getAds("app-index", listener)
    }

    /**
     * 获取疾病列表
     */
    fun getDiseases(isFristPage: Boolean, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getDiseases(isFristPage, listener)
    }

    /**
     * 获取我的预约
     * @param isFristPage 是否为第一页
     */
    fun getCalllog(isFristPage: Boolean, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getCalllog(isFristPage, listener)
    }

    /**
     * 获取地区
     * @param regionId 传1为获取所有地区
     */
    fun getRegion(regionId: Int, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getRegion(regionId, listener)
    }

    /**
     * 获取收货地址
     */
    fun getAddress(listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getAddress(listener)
    }

    /**
     * 添加地址
     * @param consignee 联系人名称
     * @param regionList [省份code，市code，区code] 可在获取省市区接口获取
     * @param address 详细地址
     * @param mobile 联系人电话
     * @param isDefault 是否默认地址
     */
    fun addAddress(consignee: String, regionList: ArrayList<Int>, address: String, mobile: String, isDefault: Int, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).addAddress(consignee, regionList, address, mobile, isDefault, listener)
    }

    /**
     * 编辑地址
     * @param userAddressId 地址ID
     * @param consignee 联系人名称
     * @param regionList [省份code，市code，区code] 可在获取省市区接口获取
     * @param address 详细地址
     * @param mobile 联系人电话
     * @param isDefault 是否默认地址
     */
    fun editAddress(userAddressId: Int, consignee: String, regionList: ArrayList<Int>, region: String, address: String,
                    mobile: String, isDefault: Int, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).editAddress(userAddressId, consignee, regionList, region, address, mobile, isDefault, listener)
    }

    /**
     * 上传头像
     *
     * @param file 头像文件
     */
    fun uploadHeadImg(file: File, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).upLoadImageFile(file, listener)
    }

    /**
     * 下载文件
     * @param url 文件地址
     * @param savePath 保存路径
     */
    fun downloadFile(url: String, savePath: String, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).downloadFile(url, savePath, listener)
    }

    /**
     * 删除地址
     * @param userAddressIds 地址ID
     */
    fun delAddress(userAddressIds: IntArray, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).delAddress(userAddressIds, listener)
    }

    /**
     * 获取最新版本APP版本信息
     */
    fun getAppNewlyVersion(listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getAppNewlyVersion(listener)
    }

    /**
     * 获取每日健康指数
     */
    fun getDaily(sday: String, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getDaily(sday, listener)
    }

    /**
     * 刷新token
     */
    fun refreshToken(listener: OperateListener) {
        LoginPresenter.getInstance(mContext).refreshToken(listener)
    }

    /**
     * 图片列表
     */
    fun getAlbum(isFristPage: Boolean, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).getAlbum(isFristPage, listener)
    }

    /**
     * 添加图片
     */
    fun addPhoto(list: ArrayList<AddPhoto.Photo>, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).addPhoto(list, listener)
    }

    /**
     * 删除图片
     */
    fun delPhoto(list: ArrayList<Int>, listener: OperateListener) {
        SystemPresenter.getInstance(mContext).delPhoto(list, listener)
    }

}